import QtQuick 2.0
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

 Popup{
    id:root
    property string type: "tip"      // 弹出框的类型 error | warn | tip
    property string msg: ""          // 显示内容
    property string bgColor: "#fff"  // 弹出框背景颜色
    property int radius: 8
    property string textColor : "black"
    property string title: "213"
    property var colorMap : {"tip":"#1989FA","warn":"yellow","error":"red"}

    closePolicy:Popup.NoAutoClose
    visible: false
    background: Rectangle{
        id:innerRec
        border.color: root.colorMap[root.type]
        border.width: 2
        implicitHeight: innerText.implicitHeight + 80
        implicitWidth: Math.max(innerText.implicitWidth + 60,300)
        radius: root.radius

        RowLayout{
           anchors.fill:innerRec
           spacing: 5

           Text {
               id:innerText
               text: root.msg
               font.pixelSize: 20
               color:root.textColor
               Layout.rightMargin: 10
               Layout.alignment: Qt.AlignCenter
           }
        }
    }

    Text {
        id: textTitle
        text: root.title
        anchors.top : parent.top
        anchors.left: parent.left
        font.pixelSize: 26
        font.bold: true
        color: root.colorMap[root.type]
        anchors.topMargin: -45
        anchors.leftMargin: -10
    }

    Rectangle {
        id: closeBtn
        width: 40
        height: 40
        color: root.colorMap[root.type]
        radius: width / 2
        anchors.top : parent.top
        anchors.right: parent.right
        anchors.topMargin: -30
        anchors.rightMargin: -30
        Text {
            id: name
            text: "X"
            anchors.centerIn: parent
            font.pixelSize: 22
            color: "#fff"
            font.bold: true
        }

        MouseArea{
            anchors.fill: parent
            onPressed: {
                parent.scale *= .9
            }
            onReleased:{
                parent.scale /= .9
                root.close()
            }
        }
    }
}
